class CardView extends eui.Component{
	public constructor() {
		super();
		this.skinName="CardViewSkin";
	}
	private leftBtn:eui.Button;
	private rightBtn:eui.Button;
	private curIndex:number=0;
	private maxLen:number=0;
	private prizeImg:eui.Image;

	protected childrenCreated(){
		this.maxLen=CardDataManager.getInstance().cardData.length;
		this.leftBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onLeft,this);
		this.rightBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onRight,this);
		this.onLeft(null);
	}
	private onLeft(e:egret.TouchEvent){
		this.curIndex--;
		if(this.curIndex<=0) this.curIndex=0;
		var cardData=CardDataManager.getInstance().getCardData(this.curIndex);
		this.updateView(cardData);
	}
	private onRight(e:egret.TouchEvent){
		this.curIndex++;
		if(this.curIndex>this.maxLen-1) this.curIndex=this.maxLen-1;
		var cardData=CardDataManager.getInstance().getCardData(this.curIndex);
		this.updateView(cardData);
	}
	private updateView(cardData:CardData){
		console.log(cardData.cardimg)
		this.prizeImg.source=cardData.cardimg;
	}
}